<?php


namespace app\admin\controller;

use app\common\library\enum\CodeEnum;

class Api extends BaseAdmin
{
    /**
     * 账户API
     *
     *
     * @return mixed
     */
    public function index(){
        return $this->fetch();
    }

    /**
     * API列表
     *
     *
     */
    public function getList(){
        $where = [];

        //组合搜索
        !empty($this->request->param('uid')) && $where['uid']
            = ['eq', $this->request->param('uid')];

        $data = $this->logicApi->getApiList($where, '*', 'create_time desc', $this->request->param('limit'));

        $this->result(
            $data && !empty($data) && $data->total() > 0 ?
                [
                    'code' => CodeEnum::SUCCESS,
                    'msg' => '',
                    'count' => $data->total(),
                    'data' => $data->items()
                ] : [
                    'code' => CodeEnum::ERROR,
                    'msg' => '暂无数据',
                    'count' => 0,
                    'data' => []
                ]
        );
    }

    /**
     * 编辑商户API信息
     *
     *
     * @return mixed
     */
    public function edit(){
        // post 是提交数据
        $this->request->isPost() && $this->result($this->logicApi->editApi($this->request->post()));
        //获取商户API信息
        $this->assign('api',$this->logicApi->getApiInfo(['id' =>$this->request->param('id')]));

        return $this->fetch();
    }

}